<?php

namespace app\company\controller;

use think\admin\Controller;
use think\admin\extend\DataExtend;
/**
 * 会议室预约管理
 * Class Index
 * @package app\paper\controller
 */
class Appointment extends Controller
{

    /**
     * 当前操作数据库
     * @var string
     */
    protected $table = 'CompanyRoomAppointment';
    /**
     * 会议室预约管理
     * @auth true
     * @menu true
     * @login true
     */
    public function index()
    {
        $this->title = '会议室预约管理';
        $this->_query($this->table)->like('username')->equal('room_id')->page();
    }
    /**
     * 列表数据处理
     */
    protected function _index_page_filter(&$data)
    {
        $room = $this->app->db->name('company_room')->where(['status'=>1])->select()->toArray();
        $roomNew=[];
        foreach ($room as $v){
            $roomNew[$v['id']]=$v;
        }
        foreach ($data as $k=>$v){
            if(isset($roomNew[$v['room_id']])){
                $data[$k]['room']=$roomNew[$v['room_id']]['name'];
            }
            switch ($v['status']){
                case 0:
                    $data[$k]['status_name']="<p>未审核</p>";
                    break;
                case 1:
                    $data[$k]['status_name']="<p style='color: #1E9FFF'>已通过</p>";
                    break;
                case 2:
                    $data[$k]['status_name']="<p style='color:red;'>已驳回</p>";
                    break;
            }
        }
    }
    /**
     *通过
     * @auth true
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function adopt()
    {
        $id = input('id');
        $this->app->db->name('company_room_appointment')->where(['id'=>$id])->update(['status'=>1]);
        $this->success("操作成功");
    }
    /**
     *驳回
     * @auth true
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function reject()
    {
        $id = input('id');
        $this->app->db->name('company_room_appointment')->where(['id'=>$id])->update(['status'=>2]);
        $this->success("操作成功");
    }




}